﻿@model  MSWeb.Implementation.WyplataZaLekcjeDodaj

@{
    ViewBag.Title = "DodawanieWplat";
}
<h2>Dodawanie wypłat za lekcje: </h2>

@if (@TempData["Error"] != null)
{
    <div class="alert alert-danger" role="alert">
        <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
        <span class="sr-only">Błąd:</span>
        @TempData["Error"]
    </div>
}
@using (Html.BeginForm("Create", "wyplata", FormMethod.Post))
{
    @Html.AntiForgeryToken()

    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <div class="form-group">
        <label class="control-label">Uczeń:</label>
        @Html.DropDownListFor(model => model.SelectedNauczyciel, Model.Nauczyciel, "-- Wybierz Nauczyciela--", new { @class = "form-control" })
    </div>

    <div class="form-group">
        <label class="control-label">Lekcje:</label>
        @Html.ListBoxFor(m => m.SelectedLekcje,
            new MultiSelectList(Model.Lekcje, "Value", "Text"),
            new { @class = "chosen", data_placeholder = "Wybierz lekcje", style = "height:100px; width:95%;", tabindex = "8" })
    </div>

    <div class="form-group">
        <label class="control-label">Typ płatności:</label>
        @Html.EnumDropDownListFor(model => model.TypWyplatyZaLekcje)
    </div>

    <div class="form-group">
        <label class="control-label">Kwota:</label>
        @Html.EditorFor(model => model.Kwota, new { htmlAttributes = new { @class = "form-control", @disabled = "disabled" } })
    </div>

    <div class="form-group">
        <label class="control-label">Komentarz:</label>
        @Html.EditorFor(model => model.Komentarz, new { htmlAttributes = new { @class = "form-control" } })
    </div>

    <div class="modal-footer">
        <input type="submit" value="Zapisz" class="btn btn-default" />
    </div>
}
<script type="text/javascript">
    $(".chosen-deselect").chosen({ allow_single_deselect: true });
    $(".chosen").chosen().change();
    $(".chosen").trigger('liszt:updated');
</script>

<script type="text/javascript">
    $(function () {
        $("#SelectedNauczyciel").change(function () {
            var selectedItem = $(this).val();
            var ddlStates = $("#SelectedLekcje");
            var statesProgress = $("#states-loading-progress");
            $('#Kwota').val(0);
            statesProgress.show();
            $.ajax({
                cache: false,
                type: "GET",
                url: "GetLessonForTeacher",
                data: { "teacherId": selectedItem },
                success: function (data) {
                    ddlStates.html('');
                    $.each(data, function (id, option) {
                        ddlStates.append($('<option></option>').prop("selected", "selected").val(option.Value).html(option.Text));
                        var val = $("#SelectedLekcje").val();                        
                            $.ajax({
                                cache: false,
                                type: "GET",
                                url: "GetPriceForTeacher?value=" + val,
                                values: { "values": val },
                                success: function (result) {
                                    $('#Kwota').val(result);
                                }
                            });
                    });
                    $("#SelectedLekcje").trigger('chosen:updated');
                    statesProgress.hide();
                }
            });
        });
        $('#SelectedLekcje').change(function () {
            var val = $("#SelectedLekcje").val();
            $.ajax({
                cache: false,
                type: "GET",
                url: "GetPriceForTeacher?value=" + val,
                values: { "values": val },
                success: function (result) {
                    $('#Kwota').val(result);
                }
            });
        });
    });
</script>